package com.example.ywj.myapplication.weixin;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioGroup;

import com.example.ywj.myapplication.R;

public class IndexActivity extends AppCompatActivity {
    RadioGroup radiogroup;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        radiogroup = findViewById(R.id.radiogroup);
        radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.radio0:
                        handlerRadio0();
                        break;
                    case R.id.radio1:
                        handlerRadio1();
                        break;
                    case R.id.radio2:
                        handlerRadio2();
                        break;
                    case R.id.radio3:
                        handlerRadio3();
                        break;
                }
            }
        });
    }
    public void handlerRadio0(){
        WeiXinFragment weiXinFragment = new WeiXinFragment();
        FragmentManager fm = getSupportFragmentManager();
        // 3.开启事务
        FragmentTransaction transaction = fm.beginTransaction();
        // 4.动态的添加
        transaction.replace(R.id.top_Content,weiXinFragment,"topFragment");
        // 5.提交
        transaction.commit();
    }
    public void handlerRadio1(){
        FindFragment findFragment = new FindFragment();
        FragmentManager fm = getSupportFragmentManager();
        // 3.开启事务
        FragmentTransaction transaction = fm.beginTransaction();
        // 4.动态的添加
        transaction.replace(R.id.top_Content,findFragment,"findFragment");
        // 5.提交
        transaction.commit();
    }
    public void handlerRadio3(){
        UserFragment userFragment = new UserFragment();
        FragmentManager fm = getSupportFragmentManager();
        // 3.开启事务
        FragmentTransaction transaction = fm.beginTransaction();
        // 4.动态的添加
        transaction.replace(R.id.top_Content,userFragment,"userFragment");
        // 5.提交
        transaction.commit();
    }
    public void handlerRadio2(){
        ContactFragment contactFragment = new ContactFragment();
        FragmentManager fm = getSupportFragmentManager();
        // 3.开启事务
        FragmentTransaction transaction = fm.beginTransaction();
        // 4.动态的添加
        transaction.replace(R.id.top_Content,contactFragment,"contactFragment");
        // 5.提交
        transaction.commit();
    }
}
